package com.lqk.java8.streamAPIExer;


import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class StreamAPIExer {
    /**
     * 1. 给定一个数字列表, 如何返回一个由每个数的平方构成的列表呢?
     * 给定[1,2,3,4,5], 返回[1,4,9,16,25]
     */
    @Test
    public void test1(){
        Integer[] nums=new Integer[]{1,2,3,4,5};
        Arrays.stream(nums)
                .map((num)->num*num)
                .forEach(System.out::println);
    }
    /**
     * 怎样用map和reduce方法数一数流中有多少个Employee
     */
    List<Employee> emps= Arrays.asList(
            new Employee("001", "张三", 18, 9999, Employee.Status.FREE),
            new Employee("002", "李四", 29, 8888, Employee.Status.BUSY),
            new Employee("003", "王二", 36, 10000, Employee.Status.VOCATION),
            new Employee("004", "麻子", 38, 12000, Employee.Status.BUSY)
    );
    @Test
    public void test(){
        Optional<Integer> reduce = emps.stream()
                .map((e) -> 1)
                .reduce(Integer::sum);
        System.out.println(reduce.get());
    }
}
